<?php
ob_start();
session_start();
include 'top3.php';
include("utils.php");
//=====================================================language=============================================
if($_SESSION['langname']=="")
{
	$language_url="languages/"."english".'/adSpaceDetails_add_language.php';
}
else
{
	$language_url="languages/".$_SESSION['langname'].'/adSpaceDetails_add_language.php';
}

include_once("$language_url");
//======================================================End============================================
main_content("mainBuySpace();");

function mainBuySpace()
{
if($_SESSION['langId']!="")
	{
		$langId=$_SESSION['langId'];
	}
	else
	{
		$langId="1";
	}

$_SESSION['type_id'] = $_REQUEST[id];
$_SESSION['site_type'] = $_REQUEST[site_type];
$adspaceID = $_REQUEST[id];
//echo "ID----->".$adspaceID;
 $sql="select s.*,adm.*,addet.adspaceType FROM ".SITEMASTER." as s,".ADSPSCEMASTER." as adm,".ADSPACEDETAILS." as addet where s.langId='".$langId."' and s.adsiteId=adm.adsiteId and addet.adspaceId=adm.adspaceId and adm.adspaceId='".$adspaceID."'";
//echo $sql;die;
$query=mysql_query($sql);
$fetAdSpDetails = mysql_fetch_array($query);
$sql1="select p.*,a.clickPerDay,a.costPerClick FROM ".PRICE." as p,".ADSPSCEMASTER." as a where p.adspaceId='".$adspaceID."' and p.adspaceId=a.adspaceId and p.duration>0 order by p.duration asc";
$query1=mysql_query($sql1);
// $fetAdSpDetails1 = mysql_fetch_array($query1);
$siteUrlReplaced = str_replace("http://","",$fetAdSpDetails[adSiteUrl]);
//echo "------->".$fetAdSpDetails[publishDate];
$explodeDate = explode(' ' ,$fetAdSpDetails[publishDate]);
$execTopCountry = mysql_query("select noOfClicks,adCountryName from adspaceTopcountries where adspaceId='".$adspaceID."' order by noOfClicks desc limit 0,5");

if(isset($_SESSION[siteuserId]) && $_SESSION[siteuserId]!='')
	$callFunction = "addtoFav();";
else
	$callFunction = "location.href='start.php'";
if(isset($_SESSION[siteuserId]) && $_SESSION[siteuserId]!='')
	$callDelFunction = "deleteFromFav();";
else
	$callDelFunction = "location.href='start.php'";
$fetFavId = mysql_fetch_array(mysql_query("select favId from adspace_favourites where adspaceId='".$adspaceID."' and userId='".$_SESSION[siteuserId]."'"));
?>
<script>
function addtoFav()
{
	
		
		location.href='include_ajax/bkendAdSpaceToFavList.php?mode=refresh&adspaceid=' + document.getElementById('hidAdSpaceId').value;
	
}
function deleteFromFav()
{
	
		
		//deleteFromFavAjax('include_ajax/',document.getElementById('hidAdSpaceId').value);
		location.href='include_ajax/bkenddeleteFromFavList.php?mode=delete&adspaceid=' + document.getElementById('hidDelAdSpaceId').value;
	
}
function submitAdToCart(type_id)
{
	frm = document.frmAdToCart;
	var ele = frm.elements["days"];
	for(var i=0;i<ele.length;i++)
	{
		if(ele[i].checked == true)
		{
			//alert(ele[i].value);
			var chkedval = ele[i].value;
			var valsp = chkedval.split(",");
			if(valsp[0]== 0 || valsp[2]==0)
			{
				document.getElementById('show_alert').style.display='';
				return false;
			}
			else
			{
				frmAdToCart.submit();
			}
		}
	}
	document.getElementById('typeid').value = type_id ;

	frmAdToCart.submit();
}
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<input type="hidden" name="hidAdSpaceId" id="hidAdSpaceId" value="<?php echo $adspaceID;?>">
<input type="hidden" name="hidDelAdSpaceId" id="hidDelAdSpaceId" value="<?php echo $fetFavId[0];?>">
<table width="98%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>   <td width="20%" valign="top"><?php include("left_pannel.php"); ?></td>
      <td width="10px">&nbsp;</td>
    <td align="left" valign="top" class="BoxContent">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td width="7" height="7" align="left" valign="top"><img src="images/red_table_ltop.jpg" alt=" " /></td>
        <td height="7" align="left" valign="top" class="red_table_top"></td>
        <td width="7" height="7" align="left" valign="top"><img src="images/red_table_rtop.jpg" alt=" " width="7" height="7" /><?php //include("left_pannel.php"); ?></td>
      </tr>
      <tr>
        <td width="7" align="left" valign="top" class="red_table_LSide">&nbsp;</td>
        <td align="left" valign="top" class="inner_contentArea"><table width="750" border="0" align="center" cellpadding="0" cellspacing="0">
          <tr>
            <td align="center" valign="top" class="sky font-18"><?php echo BUY_ADS_ON; ?> <?php echo $fetAdSpDetails[adSiteUrl]; ?></td>
          </tr>
          <tr>
            <td height="22" align="left" valign="top">&nbsp;</td>
          </tr>
          <tr>
            <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td height="6" align="left" valign="top" class="toptxt">1.<?php echo CHOOSE_LENGTH_TIME; ?></td>
              </tr>
              <tr>
                <td height="6" align="left" valign="top"></td>
              </tr>
              <tr>
                <td align="left" valign="top" class="toptxt">2.<?php echo USE_THE_CALENDER; ?></td>
              </tr>
              <tr>
                <td height="6" align="left" valign="top"></td>
              </tr>
              <tr>
                <td align="left" valign="top" class="toptxt">3.<?php echo CLICK_ADD_CART; ?></td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td height="18" align="left" valign="top">&nbsp;</td>
          </tr>	 <TR>
          <TD align="left" class="err_class">
				<?php if($_REQUEST[fav]=='yes')
					echo AD_SPACE_FAVOURITE_LIST;
					if($_REQUEST[deletefav]=='yes')
					echo AD_SPACE_REMOVE_LIST;
				?>
			</TD>
        </TR>
          <tr>
            <td align="left" valign="top"><table width="100%" border="0" style="border:#CCCCCC 1px solid;" cellspacing="0" cellpadding="0">
              <tr>
                <td width="449" align="left" valign="middle" class="sitename" style="border-right:#cccccc 1px solid;"><?php echo PURCHASE_INFORMATION; ?></td>
                <td height="23" align="left" valign="middle" class="sitename"><?php echo $fetAdSpDetails[adSpaceName]; ?></td>
              </tr>
              <tr>
                <td width="449" align="left" valign="top" class="leftboxbg" style="border-right:#cccccc 1px solid;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="5" height="13" align="left" valign="top"></td>
                    <td height="13" align="left" valign="top"></td>
                  </tr>
                  <tr>
                    <td width="5" height="22" align="left" valign="top">&nbsp;</td>
                    <td align="left" valign="top" class="toptxt">1.<?php echo RUN_ADD; ?></td>
                  </tr>
		<form name="frmAdToCart" action="advertiser_direct.php" method="POST">
		<input type="hidden" name="id" id="id" value="<?php echo $adspaceID;?>">
		<input type="hidden" name="typeid" id="typeid">
		<input type="hidden" name="tab" value="<?php echo $_REQUEST['tab']; ?>">
		<input type="hidden" name="subMenu" value="<?php echo $_REQUEST['subMenu']; ?>">
		
		<input type="hidden" name="startDate" id="startDate" value="<?php echo date('Y-m-d');?>">





                  <tr>
                    <td width="5" align="left" valign="top">&nbsp;</td>
                    <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td align="left" valign="top" class="dayboxboder"><table width="100%" border="0" cellspacing="0" cellpadding="0" >
                          <tr>
                            <td width="67" align="center" valign="middle" class="box_white">&nbsp;</td>
                            <td width="78" align="center" valign="middle" class="box_white"><?php echo DAYS; ?></td>
                            <td width="81" align="center" valign="middle" class="box_white"><?php echo AVG_CLICK; ?></td>
                            <td width="89" align="center" valign="middle" class="box_white"><?php echo AVG_CPC; ?></td>
                            <td width="117" align="center" valign="middle" class="box_white"><?php echo PRICE; ?></td>
                          </tr>

                                <?php
																$cnter = 0;
$cheked = '';																
																while($result1= mysql_fetch_array($query1)){
																$cnter++;
																if($cnter==1)
																{
$cheked = 'checked';
																	$AvgCPC = $result1[ammount];
																	
																	$AvgClicksPDay = $result1[clickPerDay];
																}
																
																if($cnter%2==1)
																{
																	$class = 'normal2';
																	$class2 = 'white';
																}
																else
																{
																	$class = 'normal';
																	$class2 = 'gray';
																}
																if($cnter==mysql_num_rows($query1))
																{
																	$style = 'style="border-bottom:#cccccc 1px solid;"';
																}

$total_adspace_price = $result1[ammount]*$result1[clickPerDay]*$result1[duration];
$total_amount_value=$result1[ammount];
																?>


                           <TR class="<?php echo $class;?>">
                                  <TD align="center" <?php echo $style;?>   class="<?php echo $class2;?>_sitename"><input type="radio" name="days" id="days" onclick="selectDate(this);" value="<?php echo $result1[duration].",".$total_adspace_price.",".$total_amount_value;?>" <?php echo $cheked;?>>
                                  </TD>
                                  <TD align="center" <?php echo $style;?>  class="<?php echo $class2;?>_sitename"><?php echo $result1[duration];?></TD>
                                  <TD align="center" <?php echo $style;?>  class="<?php echo $class2;?>_sitename"><?php echo ($result1[clickPerDay]*$result1[duration]);?></TD>
                                  <TD align="center" <?php echo $style;?>  class="<?php echo $class2;?>_sitename">$<?php echo $result1[ammount];?></TD>
                                  <TD align="center" <?php echo $style;?> class="<?php echo $class2;?>_sitename"><?php if($result1[clickPerDay] >0){
				  echo $result1[ammount]*$result1[clickPerDay]*$result1[duration]; }
							     else
				  echo $result1[ammount]*$result1[duration]; ?></TD>
                                </TR>
                                <?php } ?>
                        </table></td>
                        <td width="5" align="left" valign="top">&nbsp;</td>
                      </tr>
                    </table></td>
                  </tr>
                  <tr>
                    <td width="5" align="left" valign="top"></td>
                    <td height="11" align="left" valign="top"></td>
                  </tr>
                  <tr>
                    <td width="5" align="left" valign="top">&nbsp;</td>
                    <td height="22" align="left" valign="top" class="toptxt">2. <?php echo SELECT_START_DATE; ?></td>
                  </tr>
                  <tr>
                    <td width="5" align="left" valign="top">&nbsp;</td>
                    <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="90" align="left" valign="top">&nbsp;</td>
                        <td align="left" valign="top" bgcolor="#FFFFFF" class="calboder"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                          <!--<tr>
                            <td height="18" align="center" valign="middle" class="toptxt">Run Dates</td>
                          </tr>-->
                          <tr>
                            <td align="center" valign="middle"><?php include_once 'calender.php';?></td>
                          </tr>
                        </table></td>
                        <td width="90" align="left" valign="top">&nbsp;</td>
                      </tr>
                    </table></td>
                  </tr>
                  <tr>
                    <td width="5" height="10" align="left" valign="top"></td>
                    <td height="10" align="left" valign="top"></td>
                  </tr>
                  <tr>
                    <td align="left" valign="top">&nbsp;</td>
                    <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="90" align="left" valign="top"><a onclick="submitAdToCart(<?php echo $adspaceID;?>);" href="javascript:void(0);" class="button"><?php echo ADD_TO_CART; ?></a></td>
                        <td width="31" align="left" valign="top">&nbsp;</td>
                        <td width="168" align="left" valign="top">	<?php if(!isFavAdspace($_SESSION[siteuserId],$adspaceID)) {?>
																					<a href="javascript:void(0);" class="button" onclick="<?php echo $callFunction;?>"><?php echo ADD_TO_FAVOURITE; ?></a>
																					<?php } 
																					else
																					{?>
																					<a href="javascript:void(0);" class="button"  onclick="<?php echo $callDelFunction;?>"><?php echo REMOVE_FROM_FAVOURITE; ?></a>
																					<?php }?></td>
                        <td width="27" align="left" valign="top">&nbsp;</td>
                        <td width="111" align="left" valign="top"><a href="buy_spaceNew.php" class="button"><?php echo KEEP_SHOPPING; ?></a></td>
                        <td align="left" valign="top">&nbsp;</td>
                      </tr>
                    </table></td>
                  </tr>
                  <tr>
                    <td align="left" valign="top">&nbsp;</td>
                    <td align="left" valign="top">&nbsp;</td>
                  </tr>
                </table></td>
                <td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="69" height="20" align="left" valign="top">&nbsp;</td>
                    <td height="20" align="left" valign="top">&nbsp;</td>
                    <td width="74" height="20" align="left" valign="top">&nbsp;</td>
                  </tr>
                  <tr>
                    <td width="69" height="20" align="left" valign="top">&nbsp;</td>
                    <td height="20" align="center" valign="top" class="toptxt"><?php echo AVAILABLE; ?> : <?php echo $explodeDate[0]; ?></td>
                    <td width="74" height="20" align="left" valign="top">&nbsp;</td>
                  </tr>
                  <tr>
                    <td width="69" align="left" valign="top">&nbsp;</td>
                    <td align="center" valign="top"><img src="images/noimage.jpg" alt=" " width="96" height="96" /></td>
                    <td width="74" align="left" valign="top">&nbsp;</td>
                  </tr>
                  <tr>
                    <td width="69" height="4" align="left" valign="top"></td>
                    <td height="4" align="left" valign="top"></td>
                    <td width="74" height="4" align="left" valign="top"></td>
                  </tr>
                  <tr>
                    <td width="69" align="left" valign="top">&nbsp;</td>
                    <td height="20" align="center" valign="top" class="toptxt"><A href="javascript:void(0);" onclick="return countt('hid','adSpaceDetails.php?id=<?php echo $result[adspaceId]; ?>',<?php echo $adspaceID; ?>)"><?php echo $fetAdSpDetails[adSiteUrl]; ?></A></td>
                    <td width="74" align="left" valign="top">&nbsp;</td>
                  </tr>
                  <tr>
                    <td width="69" align="left" valign="top">&nbsp;</td>
                    <td align="center" valign="middle" class="toptxt"><?php echo SITE_RATING; ?> : <?php echo $fetAdSpDetails[adsSiteRating]; ?></td>
                    <td width="74" align="left" valign="top">&nbsp;</td>
                  </tr>
                  <tr>
                    <td width="69" align="left" valign="top">&nbsp;</td>
                    <td align="center" valign="middle">&nbsp;</td>
                    <td width="74" align="left" valign="top">&nbsp;</td>
                  </tr>
                </table></td>
              </tr>
              
            </table></td>
          </tr>
          <tr>
            <td height="8" align="left" valign="top"></td>
          </tr>
          <tr>
            <td align="left" valign="top" class="dayboxboder"><table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td width="300" align="left" valign="top" class="sitename" style="border-right:#cccccc 1px solid;"><?php echo DESCRIPTION; ?></td>
                <td width="225" align="left" valign="top" class="sitename" style="border-right:#cccccc 1px solid;"><?php echo STATISTICAL_INFORMATION; ?></td>
                <td align="left" valign="top" class="sitename" style="border-right:#cccccc 1px solid;"><?php echo IMPRESSION_COUNTRY; ?></td>
              </tr>
              <tr>
                <td width="300" align="left" valign="top" style="border-right:#cccccc 1px solid;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td align="left" valign="middle" class="box_white2"><strong><?php echo DESCRIPTION_SITE; ?></strong></td>
                  </tr>
                  <tr>
                    <td align="left" valign="top" class="box_blue2"><?php echo $fetAdSpDetails[siteDescription];?></td>
                  </tr>
                  <tr>
                    <td align="left" valign="top" class="box_white2"><strong><?php echo DESCRIPTION_AD_SPACE; ?></strong></strong></td>
                  </tr>
                  <tr>
                    <td align="left" valign="top" class="box_blue2"><?php echo stripslashes($fetAdSpDetails[description]);?></td>
                  </tr>
                  <tr>
                    <td align="left" valign="top" class="box_white2"><strong><?php echo TAGS; ?></strong></td>
                  </tr>
                  <tr>
                    <td align="left" valign="top" class="box_blue2">&nbsp;<?php echo $fetAdSpDetails[tags];?></td>
                  </tr>
                </table></td>
                <td width="225" align="left" valign="top" style="border-right:#cccccc 1px solid;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="100" height="25" align="left" valign="top" class="box_white3"><strong><?php echo AVG_CLICK_PER_DAY; ?></strong></td>
                    <td height="25" align="left" valign="top" class="box_white3"><?php echo $AvgClicksPDay;?></td>
                  </tr>
                  <tr>
                    <td width="100" align="left" valign="top" class="box_blue3"><strong><?php echo AVG_CPC; ?></strong>:&nbsp;</td>
                    <td align="left" valign="top" class="box_blue3">$<?php echo $AvgCPC;?></td>
                  </tr>
                  <tr>
                    <td width="100" align="left" valign="top" class="box_white3"><strong><?php echo AVG_IMPRESSION; ?></strong>:&nbsp;</td>
                    <td align="left" valign="middle" class="box_white3"><?php echo $fetAdSpDetails[adSiteImpression];?></td>
                  </tr>
                  <tr>
                    <td width="100" align="left" valign="top" class="box_blue3"><strong><?php echo ALEXA_RANKING; ?></strong>:&nbsp;</td>
                    <td align="left" valign="top" class="box_blue3"><?php echo getAlexaRank($siteUrlReplaced); ?></td>
                  </tr>
                  <tr>
                    <td width="100" align="left" valign="top" class="box_white3"><strong><?php echo TYPE; ?></strong>:</td>
                    <td align="left" valign="top" class="box_white3"><?php echo $fetAdSpDetails[adspaceType];?></td>
                  </tr>
                  <tr>
                    <td width="100" height="25" align="left" valign="top" class="box_blue3"><strong><?php echo MEMBER_SINCE; ?></strong>:&nbsp;</td>
                    <td height="25" align="left" valign="top" class="box_blue3"><?php echo $fetAdSpDetails[publishDate];?></td>
                  </tr>
                </table></td>
                <td align="left" valign="top" bgcolor="#f9f9f9"><table width="100%" border="0" cellspacing="0" cellpadding="0"><?php while($getTopCountry = mysql_fetch_array($execTopCountry)) 
						{
						?>
                  <tr>
                    <td height="25" align="left" valign="top" class="box_white4" style="border-bottom:#cccccc 1px solid;"><strong><?php echo ucwords($getTopCountry[1]);?></strong> <?php echo getClickPercent($fetAdSpDetails[totClicksPerDay],$getTopCountry[0]); ?> %</td>
                  </tr><?php
						}
						?>
                 <!-- <tr>
                    <td height="20" align="left" valign="top" class="box_white4"><strong>Afghanistan</strong> 66.67 %</td>
                  </tr>-->
                </table></td>
              </tr>
            </table></td>
          </tr>
          <tr>
            <td align="left" valign="top">&nbsp;</td>
          </tr>
        </table></td>
        <td width="7" align="left" valign="top" class="red_table_RSide">&nbsp;</td>
      </tr>
      <tr>
        <td width="7" align="left" valign="top"><img src="images/red_table_lbottom.jpg" alt=" " width="7" height="7" /></td>
        <td height="7" align="left" valign="top" class="red_table_bottom"></td>
        <td width="7" align="left" valign="top"><img src="images/red_table_rbottom.jpg" alt=" " width="7" height="7" /></td>
      </tr>
    </table></td>
  </tr>
</table>
<?php
       }
		?> 
</body>
</html>
